package gui.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.beans.PropertyChangeListener;

import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * 
 * @author Felix Schliephacke
 * 
 */
class NorthPanel extends JPanel {

	private static final long serialVersionUID = 2386165506059492464L;
	private MaxSolutionsChoiceBox maxSolutionsChoiceBox;
	private MaxThreadsChoiceBox maxThreadsChoiceBox;
	private JPanel north;
	private SizeChoiceBox sizeChoice;
	private JPanel south;

	public NorthPanel() {
		this.setLayout(new BorderLayout());
		this.add(this.getNorthPanel(), BorderLayout.NORTH);
		this.add(this.getSouthPanel(), BorderLayout.SOUTH);
	}

	@Override
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		this.getSizeChoiceBox().addPropertyChangeListener(listener);
		this.getMaxThreadsChoiceBox().addPropertyChangeListener(listener);
		this.getMaxSolutionsChoiceBox().addPropertyChangeListener(listener);
	}

	@Override
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		this.getSizeChoiceBox().removePropertyChangeListener(listener);
		this.getMaxThreadsChoiceBox().removePropertyChangeListener(listener);
		this.getMaxSolutionsChoiceBox().removePropertyChangeListener(listener);
	}

	private MaxSolutionsChoiceBox getMaxSolutionsChoiceBox() {
		if (this.maxSolutionsChoiceBox == null) {
			this.maxSolutionsChoiceBox = new MaxSolutionsChoiceBox();
		}
		return this.maxSolutionsChoiceBox;
	}

	private MaxThreadsChoiceBox getMaxThreadsChoiceBox() {
		if (this.maxThreadsChoiceBox == null) {
			this.maxThreadsChoiceBox = new MaxThreadsChoiceBox();
		}
		return this.maxThreadsChoiceBox;
	}

	private JPanel getNorthPanel() {
		if (this.north == null) {
			this.north = new JPanel();
			this.north.setLayout(new FlowLayout());
			this.north.add(this.getSizeChoiceBox());
			this.north.add(new JLabel("Threads:"));
			this.north.add(this.getMaxThreadsChoiceBox());
		}
		return this.north;
	}

	private SizeChoiceBox getSizeChoiceBox() {
		if (this.sizeChoice == null) {
			this.sizeChoice = new SizeChoiceBox();
		}
		return this.sizeChoice;
	}

	private JPanel getSouthPanel() {
		if (this.south == null) {
			this.south = new JPanel();
			this.south.setLayout(new FlowLayout());
			this.south.add(new JLabel("Solutions:"));
			this.south.add(this.getMaxSolutionsChoiceBox());
		}
		return this.south;
	}
}
